// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 

using System;
using System.Xml.Serialization;

namespace SoapTrace.Core.Formatters
{
	/// <summary>
	/// Holds the information about a message formatter type.
	/// </summary>
	[ XmlType( "messageFormatter" ) ]
	public class MessageFormatterEntry
	{
		/// <summary>
		/// The full name of the type ( 'Type,Assembly' ).
		/// </summary>
		private string m_FullTypeName = String.Empty;

		/// <summary>
		/// The name of the type.
		/// </summary>
		private string m_TypeName = String.Empty;

		/// <summary>
		/// The name of the assembly.
		/// </summary>
		private string m_AssemblyName = String.Empty;

		/// <summary>
		/// Creates a new instance of the <see cref="MessageFormatterEntry"/>
		/// class.
		/// </summary>
		public MessageFormatterEntry( )
		{
		}

		/// <summary>
		/// Gets or sets the full name of the type.
		/// </summary>
		[ XmlAttribute( "type" ) ]
		public string FullTypeName
		{
			get
			{
				return m_FullTypeName;
			}

			set
			{
				ParseFullTypeName( value );
				m_FullTypeName = value;
			}
		}

		/// <summary>
		/// Gets or sets the name of the type.
		/// </summary>
		[ XmlIgnore ]
		public string TypeName
		{
			get
			{
				return m_TypeName;
			}

			set
			{
				m_TypeName = value;
			}
		}

		/// <summary>
		/// Gets or sets the assembly of the type.
		/// </summary>
		[ XmlIgnore ]
		public string AssemblyName
		{
			get
			{
				return m_AssemblyName;
			}

			set
			{
				m_AssemblyName = value;
			}
		}

		/// <summary>
		/// Splits up the full type name into type and assembly parts.
		/// </summary>
		/// <param name="fullTypeName"></param>
		private void ParseFullTypeName( string fullTypeName )
		{
			int Separator = fullTypeName.IndexOf( "," );
			if( ( Separator >= 0 ) && ( Separator < ( fullTypeName.Length - 1 ) ) )
			{
				m_TypeName = fullTypeName.Substring( 0, Separator ).Trim( );
				m_AssemblyName = fullTypeName.Substring( ( Separator + 1 ) ).Trim( );
			}
			else
			{
				m_TypeName = String.Empty;
				m_AssemblyName = String.Empty;
			}
		}
	}
}
